<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        canvas{
            border: 1px solid red;
        }
    </style>
</head>
<body>
<canvas id="box" width="500" height="500">您的浏览器不支持画布</canvas>
<script type="text/javascript">
    //通过画布获取画笔
    var box=document.getElementById("box");
    var pen=box.getContext("2d");
    pen.clearRect(0,0,box.width,box.height);//清除画布

    pen.arc(250,250,200,0,Math.PI*2);
    pen.stroke();
    pen.clip();

    pen.beginPath();
    pen.moveTo(10,10);
    pen.lineTo(8,15);
    pen.lineTo(20,20);
    pen.closePath();
    pen.stroke();
    //设置当两个图像重合在一起的时候，谁在上面，谁在下面
    pen.globalCompositeOperation="source-over";
    pen.rect(100,100,300,300);
    pen.stroke();

//    var img=new Image();
//    img.src="img/clock.jpg";
//    img.onload=function(){
//        pen.drawImage(img,0,0,box.width,box.height);
//    }

</script>
</body>
</html>